var quickSearch = ""; // 快速查询
var btnAdvSearchflg = false; // 高级查询是否点击标识
var waitTable= null; // 待审核
var completeTable= null; // 待分派
var cancelTable= null; // 发货中
var adjustTableUpdate= null;
var addItemTable= null;
var searchCondition = { // 高级检索
    "createTimeS":"",
    "createTimeE":"",
    "storId":"",
    "adjustType":""
};
var mapAdjustSku = {};//新追加，修改的时候表格里面的值
var skuIdex=0;
var deleteflg = false;
var nEditing = null;
/**
 * 页面初期化
 */
$(document).ready(function() {

    //初始化
    //按钮控制
    setPageElementStatus("");
    // 构建第三方仓库下拉列表
    $.ajax({
        type: "GET",
        url : "/stock/getStor.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.result == "success") {
                $("#storId option").remove();
                $("#storId").append("<option storCode='' value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storId').append("<option storCode='" + value.storCode + "' value='" + value.storId +"'>" + value.storName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 高级检索初期化的时候隐藏
    var fromOther = "n";
    $("#advSearchPanel").hide();
    if (window.top.window.$("#q_orderTradeCode").val() != "") {
        $("#tradeCode").val(window.top.window.$("#q_orderTradeCode").val());
        window.top.window.$("#q_orderTradeCode").val("");
        fromOther = "y";
    }
    if (window.top.window.$("#orderCode").val() != "") {
        $("#orderCode").val(window.top.window.$("#orderCode").val());
        window.top.window.$("#orderCode").val("");
        fromOther = "y";
    }

    // var searchCondition = { // 高级检索
    //     "createTime":$('#createTime').val(),
    //     "storId":$('#storId').val(),
    //     "adjustType":$('#adjustType').val()
    // };

    // 高级检索初期化的时候隐藏
    $("#advSearchPanel").hide();

    $('.panel-default .datetimepicker-default').datetimepicker();
    $(".selectpicker").selectpicker({
        'noneSelectedText' : '请选择'
    });
    $(".selectpicker").selectpicker('refresh');

    //数量取得
    getCounts();
    showWaitTab();

    //事件

    // 全选，全不选
    $("#chkAll").click(function() {
        var checkboxes = document.getElementsByName('chkAdjust');
        for (var i = 0; i < checkboxes.length; i++) {
            var checkbox = checkboxes[i];
            if (!$(this).get(0).checked) {
                checkbox.checked = false;
            } else {
                checkbox.checked = true;
            }
        }
    });

    // 全选，全不选
    $("#chkAllItem").click(function() {
        var checkboxes = window.top.window.$("input:checkbox[name='chk']");
        for (var i = 0; i < checkboxes.length; i++) {
            var checkbox = checkboxes[i];
            if (!$(this).get(0).checked) {
                checkbox.checked = false;
            } else {
                checkbox.checked = true;
            }
        }
    });

    $("#btnAdvSearch").click(function() {
        btnAdvSearchflg = true;
        if ($("#advSearchPanel").is(":hidden")) {
            $("#btnQuickSearch").hide();
            $("#advSearchPanel").show();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
            $(this).children("i:eq(0)").addClass("fa-angle-double-up");
        } else {
            $("#advSearchPanel").hide();
            $("#btnQuickSearch").show();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
            $(this).children("i:eq(0)").addClass("fa-angle-double-down");
        }

    });

    /**
     * tab切换事件
     */
    $('a[data-toggle="tab"]').on('show.bs.tab', function(e) {

        switch ($(this).attr("id")) {
            case "wait": // 待审核
                showWaitTab();
                break;
            case "complete": // 已完成
                showCompleteTab();
                break;
            case "cancel": // 已废弃
                showCancelTab();
                break;
            default:
                break;
        }
        getCounts();

    });

    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
        var tables = $.fn.dataTable.tables({
            visible : true,
            api : true
        });
        if (tables.length > 0) {
            $(tables).DataTable().columns.adjust();
        }
        $(tables).find("th.sorting_asc").removeClass("sorting_asc");
    });


    // 高级搜索“提交”按钮点击
    $("#advSearchSubmit").click(function(e) {
        // 记录高级查询的检索条件
        setHidValue("frmAdvSearch");
        searchCondition = { // 高级检索
            "createTimeS":$('#createTimeS').val(),
            "createTimeE":$('#createTimeE').val(),
            "storId":$('#storId').val(),
            "adjustType":$('#adjustType').val()
        };
        quickSearch = encodeURI($('#quickSearch').val());
        $("div .active").each(function() {
            switch ($(this).attr("id")) {
                case "waitTab": // 待审核
                    showWaitTab();
                    break;
                case "completeTab": // 已完成
                    showCompleteTab();
                    break;
                case "cancelTab": // 已废弃
                    showCancelTab();
                    break;
                default:
                    break;
            }
        });
        getCounts();
    });

    /**
     * 搜索框的回车事件
     */
    $('#quickSearch').keydown(function(e){
        if(e.keyCode==13 && $('#btnQuickSearch').is(":visible")){
            $("#btnQuickSearch").click();
        }
    });


    /**
     * 快速搜索，点击时提交表格刷新内容
     */
    $("#btnQuickSearch").click(function() {
        searchCondition = { // 高级检索
            "createTimeS":$('#createTimeS').val(),
            "createTimeE":$('#createTimeE').val(),
            "storId":$('#storId').val(),
            "adjustType":$('#adjustType').val()
        };
        quickSearch = encodeURI($('#quickSearch').val());
        searchCondition = {};//点击快速查询时清空高级查询项
        $("div .active").each(function() {
            switch ($(this).attr("id")) {
                case "waitTab": // 待审核
                    showWaitTab();
                    break;
                case "completeTab": // 已完成
                    showCompleteTab();
                    break;
                case "cancelTab": // 已废弃
                    showCancelTab();
                    break;
                default:
                    break;
            }
        });
        getCounts();
    });

    $(window).resize(function(){
        var sonWidth = 0;
        $("div .active").each(function() {
            switch ($(this).attr("id")) {
                case "wait": // 待审核
                    sonWidth = $("#widthWaitTab").width()-30;
                    $("#widthWaitTab iframe").each(function () {
                        $(this).attr("width",sonWidth);
                    });
                    break;
                case "completeTab": // 已完成
                    sonWidth = $("#widthCompleteTab").width()-30;
                    $("#widthCompleteTab iframe").each(function () {
                        $(this).attr("width",sonWidth);
                    });
                    break;
                case "cancelTab": // 已废弃
                    sonWidth = $("#widthCancelTab").width()-30;
                    $("#widthCancelTab iframe").each(function () {
                        $(this).attr("width",sonWidth);
                    });
                    break;
                default:
                    break;
            }
        });
    })

    // 子表格显示隐藏
    $('.tablefirst tbody').on(
            'click',
            'td .fadu',
            function() {
                //宽度
                var sonWidth = 0;
                // 取得主键
                var adjustId = $(this).attr('adjustId');
                // 取得行
                var tr = $(this).closest('tr');
                var row;
                var table;
                var tablename = "";
                var tabIndex = "";
                $("div .active").each(function() {
                    switch ($(this).attr("id")) {
                        case "waitTab": // 待审核
                            table = waitTable;
                            row = waitTable.row(tr);
                            tablename = "waitTable";
                            tabIndex = "wait";
                            sonWidth = $("#widthWaitTab").width()-30;
                            break;
                        case "completeTab": // 已完成
                            table = completeTable;
                            row = completeTable.row(tr);
                            tablename = "completeTable";
                            tabIndex = "complete";
                            sonWidth = $("#widthCompleteTab").width()-30;
                            break;
                        case "cancelTab": // 已废弃
                            table = cancelTable;
                            row = cancelTable.row(tr);
                            tablename = "cancelTable";
                            tabIndex = "cancel";
                            sonWidth = $("#widthCancelTab").width()-30;
                            break;
                        default:
                            break;
                    }
                });
                // 加载过，而且是显示的状态
                if (row.child.isShown()) {
                    // This row is already open - close
                    // it
                    row.child.hide();
                    tr.removeClass('shown');
                    $(this).removeClass('fa-chevron-up');
                    $(this).addClass('fa-chevron-down');
                } else {
                    // 关闭其他
                    $('#' + tablename + ' tbody tr').each(function() {
                        if ($(this).attr("role") == "row") {
                            table.row($(this)).child.hide();
                        }
                    });
                    $('.fa-chevron-up').addClass('fa-chevron-down');
                    $('.fa-chevron-down').removeClass('fa-chevron-up');
                    // 生成datatable的HTML代码
                    // 判断相应的id的datatable是否存在
                    if ($('#' + tablename + adjustId + tabIndex).length <= 0) {
                        var temp = '<iframe myid="'
                            + adjustId
                            + ' tab="'
                            + tabIndex
                            + '" id="contentFrame1" name="contentFrame"  frameborder="0" src="/views/warehouse/extAdjust/extAdjustSkuList.html" width="'+sonWidth+'" height="400"></iframe>';
                        // Open this row
                        row.child(temp).show();
                        tr.addClass('shown');
                        $("#myid").val(adjustId);
                        $("#tab").val(tabIndex);
                    } else {
                        tr.addClass('shown');
                    }
                    $(this).addClass('fa-chevron-up');
                    $(this).removeClass('fa-chevron-down');
                }
            });

    //添加商品
    $("#addSku").click(function() {
        if (window.top.window.$("#storIdNew").val()==null || window.top.window.$("#storIdNew").val()==undefined || window.top.window.$("#storIdNew").val()==""){
            window.top.window.showModalAlert("请选择第三方仓库");
            return false;
        } else {
            $("#storIdSearch").val(window.top.window.$("#storIdNew").val())
        }
        $('#chkAllItem').prop("checked", false);
        window.top.window.returnCustomModalDialog();
        var editDialog = window.top.window.borrowCustomModalDialog($("#modalAddItem"));
        editDialog.modal({show:true, backdrop:'static'});
    });

    $("#btnSkuSearch").click(function(){
        doQuery();
    });

    /**
     * 添加商品/添加赠品画面的确定按钮
     */
    $("#btnAddItem").on('click',function(){
        var skuObj = new Object();
        var skuCode = new Array();
        if (window.top.window.$('input:checkbox[name=chk]:checked').length<=0){
            window.top.window.showModalAlert("请选择商品");
            return false;
        }

        window.top.window.$('input:checkbox[name=chk]:checked').each(function(i) {
            if (mapAdjustSku[$(this).attr("myid")]!=undefined){
                skuCode.push($(this).attr("myid"));
            }
        });

        if (skuCode.length>0){
            window.top.window.showModalAlert("规格商家编码-库存类型-批次-效期："+skuCode.join(",")+"的数据已经存在，不能选择");
            return false;
        }

        window.top.window.$('input:checkbox[name=chk]:checked').each(function(i) {
            skuObj.goodsCode = $(this).attr("goodscode");
            skuObj.goodsname = $(this).attr("goodsname");
            skuObj.skucode = $(this).attr("skucode");
            skuObj.skuname = $(this).attr("skuname");
            skuObj.stocktype = $(this).attr("stocktype");
            skuObj.batchcode = $(this).attr("batchcode");
            skuObj.productdate = $(this).attr("productdate");

            adjustTableUpdate.fnAddData([ skuObj.goodsCode, skuObj.goodsname, skuObj.skucode, skuObj.skuname, skuObj.stocktype, skuObj.batchcode, skuObj.productdate, '', '',
                '<a href="javascript:;" class="delete" adjustSkuId="" dataKind="MT" fileName="">删除</a>' ]);

            $("#adjustTableUpdate tbody tr:eq("+skuIdex+")").find("td").each(function () {
                $(this).attr("title",$(this).text());
            });

            mapAdjustSku[$(this).attr("myid")] = $(this).attr("myid");
            skuIdex++;
        });
        window.top.window.$("#btnAddItemClose").click();
    });

    //倒霉的表格编辑，td鼠标点击进入编辑状态
    $('#adjustTableUpdate').on('click', 'td', function(e) {
        if (deleteflg == true) {
            deleteflg = false;
            return;
        }
        deleteflg = false;
        // e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        if (nEditing !== null && nEditing != nRow) {
            saveRow(adjustTableUpdate, nEditing);
            editRow(adjustTableUpdate, nRow);
            nEditing = nRow;
        } else {
            var text = $(this).parent().find("input");
            if (text.length <= 0) {
                editRow(adjustTableUpdate, nRow);
            }
            nEditing = nRow;
        }
    });

    // $('#adjustTableUpdate').on('click', 'a.back', function(e) {
    //     deleteflg = true;
    //     e.preventDefault();
    //     var nRow = $(this).parents('tr')[0];
    //     if (nEditing !== null && nEditing != nRow) {
    //         saveRow(adjustTableUpdate, nEditing);
    //     }
    //     adjustTableUpdate.fnUpdate('<a href="javascript:;" class="deleteU" adjustSkuId="'+$(this).attr("adjustSkuId")+'"'+' dataKind="'+$(this).attr("dataKind")+'"'+' fileName="'+$(this).attr("fileName")+'">删除</a>', nRow, 9, false);
    //     nEditing = null;
    // });

    /**
     * 要变成恢复的删除按钮
     */
    $('#adjustTableUpdate').on('click', 'a.deleteU', function(e) {
        deleteflg = true;
        e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        // $(this).parents('tr:eq(0)').hide();
        // if (nEditing !== null && nEditing != nRow) {
        //     saveRow(adjustTableUpdate, nEditing);
        // }
        window.top.window.$("#modalConfirmContent").text("要删除该行吗?");
        window.top.window.$('#btnModalOK').unbind();
        window.top.window.$("#btnModalOK").on('click', '', {
            nRow : nRow,
            adjustSkuId:$(this).attr("adjustSkuId"),
            dataKind:$(this).attr("dataKind"),
            fileName:$(this).attr("fileName")
        }, deladjustSku1);
        window.top.window.$('#modal-confirm').modal({
            show : true,
            backdrop : 'static'
        });

        // adjustTableUpdate.fnUpdate('<a href="javascript:;" class="back" adjustSkuId="'+$(this).attr("adjustSkuId")+'"'+' dataKind="'+$(this).attr("dataKind")+'"'+' fileName="'+$(this).attr("fileName")+'"><font style="color:red">已删除</font></a>', nRow, 9, false);
        // nEditing = null;
        // var aData = adjustTableUpdate.fnGetData(nRow);
        // delete mapAdjustSku[aData[2]+"-"+aData[4]+"-"+aData[5]+"-"+aData[6]];
    });

    /**
     * 要删除行的删除按钮
     */
    $('#adjustTableUpdate').on('click', 'a.delete', function(e) {
        deleteflg = true;
        e.preventDefault();
        var nRow = $(this).parents('tr')[0];
        window.top.window.$("#modalConfirmContent").text("要删除该行吗?");
        window.top.window.$('#btnModalOK').unbind();
        window.top.window.$("#btnModalOK").on('click', '', {
            nRow : nRow,
        }, deladjustSku);
        window.top.window.$('#modal-confirm').modal({
            show : true,
            backdrop : 'static'
        });
    });

    // 设置规则详情对话框关闭事件发生
    $('#modalAddItem').on('hide.bs.modal', function () {
        // 父窗体归还本页的编辑对话框
        window.top.window.$("#frmSelPrjSku")[0].reset();
        window.top.window.$('#addItemTable tbody').html("");
        window.top.window.returnCustomModalDialog();
        window.top.window.borrowCustomModalDialog($("#newAdjustPage"));

    })

    // 设置规则详情对话框关闭事件发生
    $('#modalDownFile').on('hide.bs.modal', function () {
        // 父窗体归还本页的编辑对话框
        window.top.window.returnCustomModalDialog();
        window.top.window.borrowCustomModalDialog($("#newAdjustPage"));

    })

    $("#modalDownFile").on('show.bs.modal',function(){
        file = $("#upload-file");
        file.after(file.clone().val(""));
        file.remove()
        $("#upload-file").unbind("change").bind("change", importf);
    });

    //下载模板
    $('#downloadExcel').click(function() {
        window.location.href="/views/warehouse/extAdjust/extAdjust.xls";
    });


    // 创建分单规则对话框关闭事件发生
    $('#newAdjustPage').on('hide.bs.modal', function() {
        // 父窗体归还本页的编辑对话框
        window.top.window.returnCustomModalDialog();
    });

    $("#clearAll").click(function(){
        window.top.window.$("#adjustTableUpdate tbody tr").each(function() {
            mapAdjustSku={};
            adjustTableUpdate.fnDeleteRow($(this));
        });
        nEditing = null;
    });

    // 创建保存按钮点击事件绑定
    $("#btnAdjustAdd").click(function() {
        var rule1 = /^-?\d+$/;
        var row = 0;
        var deletRow = 0;
        var msg = "";
        var adjust=new Object();
        var adjustSku=new Array();

        if (window.top.window.$("#storIdNew").val()==null || window.top.window.$("#storIdNew").val()=="" || window.top.window.$("#storIdNew").val()==undefined){
            window.top.window.showModalAlert("请选择第三方仓库");
            return false;
        }

        // 表值同步
        if (nEditing != null) {
            saveRow(adjustTableUpdate, nEditing);
            nEditing = null;
        }

        window.top.window.$('#adjustTableUpdate tbody tr').each(function(index) {
            var aData = adjustTableUpdate.fnGetData(this);
            if (aData==null){
                return false;
            }
            row++;
            var batchCode = "";
            var productDate = "";
            if (aData[5] != null && aData[5] != undefined && $.trim(aData[5]) != ''){
                batchCode = aData[5];
            }
            if (aData[6] != null && aData[6] != undefined && $.trim(aData[6]) != ''){
                productDate = aData[6];
            }
            if (aData[7] == null || aData[7] == undefined || $.trim(aData[7]) == ''){
                if(batchCode!=""){
                    msg = "调整数是必填项不能为空，请确认后再保存";
                    // msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+" 批次："+batchCode+" 效期："+productDate+") 的调整数量必须输入";
                } else {
                    // msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+") 的调整数量必须输入";
                    msg = "调整数是必填项不能为空，请确认后再保存";
                }

                return false;
            } else {
                if(!rule1.test(aData[7])){
                    if(batchCode!=""){
                        msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+" 批次："+batchCode+" 效期："+productDate+") 的数量输入格式有问题";
                    } else {
                        msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+") 的数量输入格式有问题";
                    }
                    return false;
                }

                if (aData[7]==0){
                    if(batchCode!=""){
                        msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+" 批次："+batchCode+" 效期："+productDate+") 的数量不能为0";
                    } else {
                        msg = "(规格商家编码："+aData[2]+" 库存类型："+aData[4]+") 的数量不能为0";
                    }

                    return false;
                }
            }
            var sku = new Object();
            sku.skuCode = aData[2];
            sku.goodsCode = aData[0];
            sku.qty = aData[7];
            sku.stockType = aData[4];
            sku.remark = aData[8];
            if ($(this).find("a").html().indexOf("已删除")!=-1){
                sku.deleted = "y";
                deletRow++;
            } else {
                sku.deleted = "n";
            }
            if ($(this).find("a").attr("adjustskuid")!=null && $(this).find("a").attr("adjustskuid")!=undefined && $(this).find("a").attr("adjustskuid")!=""){
                sku.action = "update";
                sku.adjustSkuId = $(this).find("a").attr("adjustskuid");
                sku.dataType = $(this).find("a").attr("dataKind");
                sku.fileName = $(this).find("a").attr("fileName");
            } else {
                sku.action = "insert";
                sku.adjustId = window.top.window.$("#adjustId").val();
                sku.dataType = $(this).find("a").attr("dataKind");
                sku.fileName = $(this).find("a").attr("fileName");
            }
            adjustSku.push(sku);
        });

        if (row > 0) {
            if (msg!=""){
                window.top.window.showModalAlert(msg);
                return;
            }
            if (deletRow==row){
                window.top.window.showModalAlert("明细数据已经全部是删除状态");
                return;
            }
        } else {
            window.top.window.showModalAlert("商品明细列表为空");
            return;
        }
        adjust.adjustId = window.top.window.$("#adjustId").val();
        adjust.storId = window.top.window.$("#storIdNew").val();
        adjust.remark = window.top.window.$("#remarkNew").val();
        adjust.adjustSku = adjustSku;

        var loading = window.top.window.getIndexBusyOverlay();
        $.ajax({
            type : "POST",
            url : "/extAdjust/createAdjust.action",
            data : JSON.stringify(adjust),
            contentType : "application/json;charset=utf-8",
            dataType : "json",
//            async : false, // 同步
            beforeSend:function(){
                if(loading) {
                	loading.settext("正在处理中，请稍后...");
                }
            },
            success : function(data) {
            	loading.remove();
                window.top.window.returnCustomModalDialog();
                if (data.result == "success") {
                    $('#newAdjustPage').modal('hide');
                    $("div .active").each(function() {
                        switch ($(this).attr("id")) {
                            case "waitTab": // 待审核
                                showWaitTab();
                                break;
                            case "completeTab": // 已完成
                                showCompleteTab();
                                break;
                            case "cancelTab": // 已废弃
                                showCancelTab();
                                break;
                            default:
                                break;
                        }
                    });
                    window.top.window.$("#btnOrderCancel").click();
                    window.top.window.showScoMessage('ok', '数据更新成功');
                    refresh()
                } else {
                    window.top.window.showModalAlert(data.msg);
                    var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
                    editDialog.modal({
                        show : true,
                        backdrop : 'static'
                    });
                }
            },
            error : function(XMLHttpRequest, textStatus) {
            	loading.remove();
                if (XMLHttpRequest.status == 500) {
                    var result = eval("(" + XMLHttpRequest.responseText + ")");
                    alert(result.errorObject.errorText);
                }
            }
        });

    });
});

/**
 * 取得tab上面的数字
 *
 * @returns
 */
function getCounts() {
    var returnValue  = "";
    // 未付款数字,待处理数字,待发货,全部发货,已完成数字,已废弃数字
    $.ajax({
        type : "POST",
        url : "/extAdjust/getTabCounts.action?quickSearch=" + quickSearch,
        data : JSON.stringify(searchCondition),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                $("#wait").html("待调整(" + data.countWait + ")");
                $("#complete").html("已调整(" + data.countComplete + ")");
                $("#cancel").html("已废弃(" + data.countCancel + ")");

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 待调整 列表
 *
 * @returns
 */
function showWaitTab() {
    $("#cancelAdjust").show();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (waitTable != null && waitTable != undefined && "" != waitTable) {
        waitTable.draw();
        return;
    }
    waitTable = $('#waitTable').DataTable({
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "processing" : true,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/extAdjust/getWaitTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "chk"
        }, {
                "data" : "adjustCode"
            }, {
                "data" : "sourceCode"
            }, {
                "data" : "storName"
            }, {
                "data" : "adjustTypeName"
            }, {
                "data" : "createUser"
            }, {
                "data" : "createTime"
            }, {
                "data" : "remark"
            }, {
                "data" : "operation"
            } ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "orderable" : false,
            "targets" : [ 1 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }, {
            "orderable" : false,
            "targets" : [ 9 ]
        }],

        "order" : [ [7, "desc" ] ]
    }).on('draw.dt',  function() {
        //解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        $("#waitTable").find("th.sorting_asc").removeClass("sorting_asc");
    });

}
$("#waitTable").tooltip({
    selector: ".tooltip-column-detail",
    container: "body",
    title: function() {
        if ($(this)[0].scrollWidth > $(this).outerWidth()) {
            return $(this).text();
        }
    }
});
/**
 * 已经调整 列表
 *
 * @returns
 */
function showCompleteTab() {
    $("#cancelAdjust").hide();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (completeTable != null && completeTable != undefined && "" != completeTable) {
        completeTable.draw();
        return;
    }
    completeTable = $('#completeTable').DataTable({
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "processing" : true,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/extAdjust/getCompleteTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "adjustCode"
        }, {
            "data" : "sourceCode"
        }, {
            "data" : "storName"
        }, {
            "data" : "adjustTypeName"
        }, {
            "data" : "createUser"
        }, {
            "data" : "createTime"
        }, {
            "data" : "adjustTime"
        }, {
            "data" : "remark"
        }],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 1 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 8 ]
        }],

        "order" : [ [6, "desc" ] ]
    }).on('draw.dt',  function() {
        //解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        $("#completeTable").find("th.sorting_asc").removeClass("sorting_asc");
    });

}
$("#completeTable").tooltip({
    selector: ".tooltip-column-detail",
    container: "body",
    title: function() {
        if ($(this)[0].scrollWidth > $(this).outerWidth()) {
            return $(this).text();
        }
    }
});
/**
 * 已经废弃 列表
 *
 * @returns
 */
function showCancelTab() {
    $("#cancelAdjust").hide();

    // 如果已经初期化过，不用重新定义，直接重画表格
    if (cancelTable != null && cancelTable != undefined && "" != cancelTable) {
        cancelTable.draw();
        return;
    }
    cancelTable = $('#cancelTable').DataTable({
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "processing" : true,
        "serverSide" : true,
        "lengthMenu" : [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100, 500, 1000 ] ],
        "dom" : '<"bottom"rtflp>',
        "searching" : false,
        "pagingType" : "full_numbers",
        "deferRender" : true,
        "ajax" : {
            "url" : "/extAdjust/getCancelTable.action",
            "data" : function(d) {
                d.quickSearch = quickSearch;
                d.formJson = JSON.stringify(searchCondition);
            }
        },
        "tableTools" : {
            "sRowSelect" : "bootstrap"
        },
        "columns" : [ {
            "data" : "sonShow"
        }, {
            "data" : "adjustCode"
        }, {
            "data" : "sourceCode"
        }, {
            "data" : "storName"
        }, {
            "data" : "adjustTypeName"
        }, {
            "data" : "createUser"
        }, {
            "data" : "createTime"
        }, {
            "data" : "remark"
        }],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 1 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }],

        "order" : [ [6, "desc" ] ]
    }).on('draw.dt',  function() {
        //解决因滚动条导致的列对不齐问题
        $(".dataTables_scrollBody").css("overflow-y","overlay");
        $("#cancelTable").find("th.sorting_asc").removeClass("sorting_asc");
    });
}
$("#cancelTable").tooltip({
    selector: ".tooltip-column-detail",
    container: "body",
    title: function() {
        if ($(this)[0].scrollWidth > $(this).outerWidth()) {
            return $(this).text();
        }
    }
});
/**
 * 主画面的列表刷新
 *
 * @returns
 */
function refresh() {
    $('#quickSearch').val("");
    quickSearch = "";
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();
    }
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
            case "waitTab": // 待审核
                showWaitTab();
                break;
            case "completeTab": // 已完成
                showCompleteTab();
                break;
            case "cancelTab": // 已废弃
                showCancelTab();
                break;
            default:
                break;
        }
    });
    getCounts();
}

/**
 * 将画面上的控件的数据的值，设置到相应的hidden控件里面
 */
function setHidValue(formId) {

    $("#"+formId + " input:hidden").each(function(){
        var id = $(this).attr('id');
        id=id.substr(3);
        var value = "";
        switch ($("#"+id).attr("type")) {
            case "text":
                value = $("#"+id).val();
                break;
            case "checkbox":
                if($("#"+id).attr('checked')){
                    value = $("#"+id).val();
                }
                break;
            case "radio":
                if($("#"+id).attr('checked')){
                    value = $("#"+id).val();
                }
                break;
            default:
                value = $("#"+id).val();
                break;
        }
        $(this).val(value);
    });
}

/**
 * 新增
 */
function newAdjust(){
    file = $("#upload-file");
    file.after(file.clone().val(""));
    file.remove()
    $("#adjustId").val("");
    mapAdjustSku={};
    skuIdex=0;
    $("#newAdjustPageTitle").html("新增调整单");
    // 构建第三方仓库下拉列表
    $.ajax({
        type: "GET",
        url : "/stock/getExtStor.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                $("#storIdNew option").remove();
                $("#storIdNew").append("<option storCode='' value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storIdNew').append("<option storCode='" + value.storCode + "' value='" + value.storId +"'>" + value.storName + "</option>");
                });
                refresh();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    //备注清空
    $("#remarkNew").val("");
    $("#clearAll").show();
    $('#adjustTableUpdate').dataTable().fnClearTable();

    // 规格新规列表
    if (adjustTableUpdate == null) {
        adjustTableUpdate = $('#adjustTableUpdate').dataTable({
            "bPaginate" : false,
            "bAutoWidth" : true,
            "bSort" : false,
            "searching" : false,
            "bDeferRender" : true,
            "bDestroy" : true,
            "dom" : '<"bottom"rtflp>',
            // "columnDefs" : [ {
            //     "className" : " text-right",
            //     "targets" : [ 5 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 6 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 7 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 8 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 9 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 10 ]
            // }]
        });
    }
    $("#upload-file").unbind("change").bind("change", importf);
    var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}
function adjust(adjustId){
    window.top.window.$("#modalConfirmContent").text("确定执行调整操作吗?");
    window.top.window.$('#btnModalOK').unbind();
    window.top.window.$("#btnModalOK").on('click', '', {
        id : adjustId
    }, doAdjust);
    window.top.window.$('#modal-confirm').modal({
        show : true,
        backdrop : 'static'
    });
}

function doAdjust(event) {
    var flg = "0";
    $.ajax({
        type : "POST",
        url : "/extAdjust/doAdjust.action?adjustId=" + encodeURI(event.data.id),
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        async : false,// 同步
        success : function(data) {
            if (data.result == "success") {
                if (data.msg) {
                    var reg = new RegExp(/\\n/,"g");
                    var errormessage = data.msg.replace(reg, "<br/>");
                    window.top.window.showModalAlertPretty(errormessage);
                } else {
                    flg = "1";
                    window.top.window.showModalAlertPretty("调整成功");
                }

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
    if ("1"==flg){
        refresh();
    }
}

function updateAdjust(adjustId){
    $("#storIdNew").val("");
    $("#remarkNew").val("");
    $("#adjustId").val(adjustId);
    $("#newAdjustPageTitle").html("修改调整单");
    file = $("#upload-file");
    file.after(file.clone().val(""));
    file.remove()
    mapAdjustSku={};
    skuIdex=0;
    // 构建第三方仓库下拉列表
    $.ajax({
        type: "GET",
        url : "/stock/getExtStor.action",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                $("#storIdNew option").remove();
                $("#storIdNew").append("<option storCode='' value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storIdNew').append("<option storCode='" + value.storCode + "' value='" + value.storId +"'>" + value.storName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    // 规格新规列表
    if (adjustTableUpdate == null) {
        adjustTableUpdate = $('#adjustTableUpdate').dataTable({
            "bPaginate" : false,
            "bAutoWidth" : true,
            "bSort" : false,
            "searching" : false,
            "bDeferRender" : true,
            "bDestroy" : true,
            "dom" : '<"bottom"rtflp>',
            // "columnDefs" : [ {
            //     "className" : " text-right",
            //     "targets" : [ 5 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 6 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 7 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 8 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 9 ]
            // },{
            //     "className" : " text-right",
            //     "targets" : [ 10 ]
            // }]
        });
    }
    $('#adjustTableUpdate').dataTable().fnClearTable();

    //检索数据
    //adjust
    $.ajax({
        type: "GET",
        url: "/extAdjust/getAdjustInfo.action?adjustId=" + adjustId,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success: function (data) {
            if (data.result == "success") {
                $("#storIdNew").val(data.data.storId);
                $("#remarkNew").val(data.data.remark);
                $("#adjustId").val(data.data.adjustId);
                $("#clearAll").hide();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    //Adjustsku
    $.ajax({
        type:"GET",
        url:"/extAdjust/getAdjustSku.action?adjustId="+adjustId,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success:function(data) {
            if (data.result == "success") {
                orderSkuRowIndex = 0;
                //设置规格信息
                $.each(data.data, function (n, value) {
                    var stocktype = "";
                    if ("zp"==value.stockType){
                        stocktype = "正品";
                    } else {
                        stocktype = "次品";
                    }
                    var deleteButten;
                    if (value.deleted=="n"){
                        deleteButten = '<a href="javascript:;" class="deleteU" adjustSkuId="'+value.adjustSkuId+'" dataKind ="'+value.dataType+'">删除</a>';
                    } else {
                        deleteButten = '<a href="javascript:;" class="back" adjustSkuId="'+value.adjustSkuId+'" dataKind ="'+value.dataType+'"><font style="color:red">恢复</font></a>';
                    }
                    adjustTableUpdate.fnAddData([ value.goodsCode, value.goodsName, value.skuCode, value.skuName, stocktype, value.batchCode, value.productDate, value.qty, value.remark,
                        deleteButten ]);

                    $("#adjustTableUpdate tbody tr:eq("+skuIdex+")").find("td").each(function () {
                        $(this).attr("title",$(this).text());
                    });
                    var batchCode = "";
                    var productDate = "";
                    if (value.batchCode!=null && value.batchCode!=undefined && value.batchCode!=""){
                        batchCode = value.batchCode;
                    }
                    if (value.productDate!=null && value.productDate!=undefined && value.productDate!=""){
                        productDate = value.productDate;
                    }
                    var myId = value.skuCode + "-" + stocktype + "-" + batchCode + "-" + productDate;
                    mapAdjustSku[myId] = myId;
                    skuIdex++;
                });
                // $("#newOrderTable").find("tr").each(function () {
                //     for(var i=0;i<20;i++){
                //         $(this).children('td:eq('+i+')').attr("title", $(this).children('td:eq('+i+')').text());
                //     }
                // });

            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error:function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });

    nEditing = null;
    $("#upload-file").unbind("change").bind("change", importf);
    var editDialog = window.top.window.borrowCustomModalDialog($("#newAdjustPage"));
    editDialog.modal({
        show : true,
        backdrop : 'static'
    });
}
/**
 * 查询第三方仓库的商品
 *
 * @returns
 */
function doQuery() {

    var advData = {
        "goodsCode" : encodeURI(window.top.window.$('#skuGoodsCode').val()),
        "goodsName" : encodeURI(window.top.window.$('#skuGoodsName').val()),
        "skuCode" : encodeURI(window.top.window.$('#skuSkuCode').val()),
        "skuName" : encodeURI(window.top.window.$('#skuSkuName').val()),
        "storId" : encodeURI(window.top.window.$('#storIdSearch').val())
    };


    addItemTable = window.top.window.$('#addItemTable').DataTable({
        "scrollX" : "100%",
        "scrollY" : "410px",
        "scrollCollapse" : false,
        "bPaginate": false,
        "bAutoWidth": true,
        "processing": true,
        "serverSide": true,
        "dom": '<"bottom"rtfli>',
        "searching": false,
        "deferRender": true,
        "info": false,
        "destroy":true,
        "ajax": {
            "url" : "/stock/getSkuList.action?formJson="+encodeURI(JSON.stringify(advData)),
        },
        "tableTools": {
            "sRowSelect": "bootstrap"
        },
        "columns": [{
            "data": "chk"
        }, {
            "data": "goodsCode"
        }, {
            "data": "goodsName"
        }, {
            "data": "skuCode"
        }, {
            "data": "skuName"
        }, {
            "data": "stockType"
        }, {
            "data": "batchCode"
        }, {
            "data": "productDate"
        }
        ],
        "columnDefs" : [ {
            "orderable" : false,
            "targets" : [ 0 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 1 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 2 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 3 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 4 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 5 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 6 ]
        }, {
            "className" : "truncate-text tooltip-column-detail",
            "targets" : [ 7 ]
        }],
        "order" : [ [ 2, "asc" ]]
    });
}

$("#addItemTable").tooltip({
    selector: ".tooltip-column-detail",
    container: "body",
    title: function() {
        if ($(this)[0].scrollWidth > $(this).outerWidth()) {
            return $(this).text();
        }
    }
});

function deladjustSku(event) {
    if (nEditing !== null && nEditing != event.data.nRow) {
        saveRow(adjustTableUpdate, nEditing);
    }
    var aData = adjustTableUpdate.fnGetData(event.data.nRow);

    delete mapAdjustSku[aData[2]+"-"+aData[4]+"-"+aData[5]+"-"+aData[6]];

    // 删除数据库存在的数据的时候，需要记录
    adjustTableUpdate.fnDeleteRow(event.data.nRow);
    adjustTableUpdate.fnDraw();
    nEditing = null;
}

function deladjustSku1(event){
    // $(this).parents('tr:eq(0)').hide();
    window.top.window.$("#adjustTableUpdate tbody tr:eq("+event.data.nRow._DT_RowIndex+")").hide();
    if (nEditing !== null && nEditing != event.data.nRow) {
        saveRow(adjustTableUpdate, nEditing);
    }
    adjustTableUpdate.fnUpdate('<a href="javascript:;" class="back" adjustSkuId="'+event.data.adjustSkuId+'"'+' dataKind="'+event.data.dataKind+'"'+' fileName="'+event.data.fileName+'"><font style="color:red">已删除</font></a>', event.data.nRow, 9, false);
    nEditing = null;
    var aData = adjustTableUpdate.fnGetData(event.data.nRow);
    delete mapAdjustSku[aData[2]+"-"+aData[4]+"-"+aData[5]+"-"+aData[6]];
}

// 跟新数据到表格上
function saveRow(oTable, nRow) {
    var rInputs = $('input', nRow);
    var aData = oTable.fnGetData(nRow);
    if (rInputs.length <= 0) {
        return;
    }
    oTable.fnUpdate(rInputs[0].value, nRow, 7, false);// 数量
    oTable.fnUpdate(rInputs[1].value, nRow, 8, false);// 备注
    oTable.fnDraw();
}

// 表格数据变为输入控件
function editRow(oTable, nRow) {
    var aData = oTable.fnGetData(nRow);
    var rTds = $('>td', nRow);
    if (rTds[9].innerHTML.indexOf("已删除")==-1){
        rTds[7].innerHTML = '<input type="text" maxlength="8" class="form-control input-small getDiscount" value="' + aData[7] + '" tableRowIndex="'
            + nRow.rowIndex + '">';// 数量
        if (aData[8]!=null && aData[8]!="" && aData[8]!=undefined){
            rTds[8].innerHTML = '<input type="text" maxlength="200" class="form-control input-small getActualPrice" value="' + aData[8] + '" tableRowIndex="'
                + nRow.rowIndex + '">';// 备注
        } else {
            rTds[8].innerHTML = '<input type="text" maxlength="200" class="form-control input-small getActualPrice" value="' + "" + '" tableRowIndex="'
                + nRow.rowIndex + '">';// 备注
        }

    }
}

/**
 * 废弃调整单
 *
 * @returns
 */
function cancelAdjust() {
    var adjustArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
            case "waitTab": // 待审核
                $('input:checkbox[name=chkAdjust]:checked').each(function(i) {
                    adjustArry.push($(this).attr("adjustid"));
                });
                break;
            case "completeTab": // 已完成
                break;
            case "cancelTab": // 已废弃
                break;
            default:
                break;
        }
    });
    if (adjustArry.length<=0){
        window.top.window.showModalAlert("请选择数据");
        return false;
    }
    window.top.window.showModalConfirm("废弃该调整单，将不能对库存信息调整，是否继续？", adjustCancel);
}

/**
 * 废弃调整单
 *
 * @returns
 */
function adjustCancel(){
    var adjustArry = new Array();
    $("div .active").each(function() {
        switch ($(this).attr("id")) {
            case "waitTab": // 待审核
                $('input:checkbox[name=chkAdjust]:checked').each(function(i) {
                    adjustArry.push($(this).attr("adjustid"));
                });
                break;
            case "completeTab": // 已完成
                break;
            case "cancelTab": // 已废弃
                break;
            default:
                break;
        }
    });

    var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "POST",
        url : "/extAdjust/adjustCancel.action",
        // contentType : "application/json;charset=utf-8",
        // dataType : "json",
        data:{"adjustId":adjustArry.join(",")},
//        async : true,// 同步
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                if (data.msg){
                    window.top.window.showModalAlert(data.msg);
                }
                refresh();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}